Skip to content

feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata#8694

Merged
OGPoyraz merged 20 commits into
mainfrom
ogp/fiat-order-txhash-implementation
May 12, 2026
Merged

feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata#8694
OGPoyraz merged 20 commits into
mainfrom
ogp/fiat-order-txhash-implementation

Conversation

@OGPoyraz
Copy link
Copy Markdown
Member

@OGPoyraz OGPoyraz commented May 5, 2026

Explanation

1. Derive fiat order sourceAmount from on-chain tx data

Currently, the fiat submit flow derives sourceAmountRaw from order.cryptoAmount - a human-readable value reported by the on-ramp provider. This value may not precisely reflect what was actually received on-chain.

This PR reads the actual transferred amount from the completed on-chain transaction (order.txHash) instead. For native tokens, the amount is taken from tx.value. For ERC-20 tokens, the amount is decoded from the transfer(address,uint256) call data. If the on-chain read fails or the transaction hash is missing, the existing order.cryptoAmount derivation is used as a fallback.

The implementation introduces:

  • getTransferredAmountFromTxHash - a generic utility in utils/transaction-receipt.ts that reads transferred amounts from any on-chain transaction (native or ERC-20). Takes explicit chainId and tokenAddress params for reusability.
  • resolveSourceAmountRaw - a fiat-strategy-specific function in strategy/fiat/utils.ts that orchestrates the on-chain read with order.cryptoAmount fallback.
  • getRawSourceAmountFromOrderCryptoAmount - the existing decimal-shift conversion, moved from fiat-submit.ts to strategy/fiat/utils.ts and renamed for clarity.

2. Persist fiat order metadata on metamaskPay

The TransactionPayController state is cleaned up when a transaction is finalized (confirmed/failed/dropped). This means fiatPayment.orderId and the provider info are gone by the time the user opens the activity/transaction-details view.

To enable the mobile activity view to show a fiat order status row (and query RampsController:getOrder for live status), this PR persists the fiat order ID and provider code on transaction.metamaskPay before polling begins in submitFiatQuotes.

Changes:

  • MetamaskPayMetadata (transaction-controller/types.ts) — Added fiatOrderId?: string and fiatProvider?: string fields.
  • submitFiatQuotes (fiat-submit.ts) — Calls updateTransaction to persist fiatOrderId and fiatProvider on tx.metamaskPay before waitForOrderCompletion starts polling. This ensures data is available even while the order is still in-flight.
  • Tests — Two new tests verify metadata persistence and that existing metamaskPay fields are preserved.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Updates fiat on-ramp submission to depend on on-chain receipt/trace parsing and persists new metadata onto TransactionMeta, which could affect payment execution and activity display if RPC methods/log parsing behave unexpectedly across networks.

Overview
Fiat on-ramp submit flow now persists order identifiers onto transaction.metamaskPay.fiat (order ID + provider code) before polling, so downstream activity views can query order status even after controller state cleanup.

The relay leg’s sourceAmountRaw is now derived from the actual on-chain transfer referenced by order.txHash via new utilities that parse ERC-20 Transfer logs or native transfers (using debug_traceTransaction with a tx.value fallback), falling back to order.cryptoAmount conversion when on-chain reads are unavailable.

Adds MetamaskPayMetadata.fiat to the transaction-controller types and updates/extends unit tests around fiat submission, amount resolution, and receipt/trace parsing.

Reviewed by Cursor Bugbot for commit 46177a2. Bugbot is set up for automated code reviews on this repo. Configure here.

@OGPoyraz OGPoyraz requested review from a team as code owners May 5, 2026 11:40
@OGPoyraz OGPoyraz changed the title feat: derive fiat order source amount from on-chain tx data feat: Derive fiat order sourceAmount from on-chain tx data May 5, 2026
Comment thread packages/transaction-pay-controller/src/strategy/fiat/utils.ts
Comment thread packages/transaction-pay-controller/src/utils/transaction-receipt.ts Outdated
@OGPoyraz OGPoyraz changed the title feat: Derive fiat order sourceAmount from on-chain tx data feat: Derive fiat order sourceAmount from on-chain tx data and persist fiat order metadata May 11, 2026
Comment thread packages/transaction-controller/src/types.ts Outdated
Comment thread packages/transaction-pay-controller/src/utils/transaction-receipt.ts Outdated
Comment thread packages/transaction-pay-controller/src/utils/transaction-receipt.ts Outdated
Comment thread packages/transaction-pay-controller/src/utils/transaction-receipt.ts Outdated
Comment thread packages/transaction-pay-controller/src/utils/transaction-receipt.ts Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bf1e13a. Configure here.

Comment thread packages/transaction-pay-controller/src/utils/transaction.ts
@OGPoyraz OGPoyraz requested a review from matthewwalsh0 May 12, 2026 11:36
@OGPoyraz OGPoyraz enabled auto-merge May 12, 2026 11:37
matthewwalsh0
matthewwalsh0 previously approved these changes May 12, 2026
@OGPoyraz OGPoyraz added this pull request to the merge queue May 12, 2026
Merged via the queue into main with commit d126223 May 12, 2026
366 checks passed
@OGPoyraz OGPoyraz deleted the ogp/fiat-order-txhash-implementation branch May 12, 2026 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants